//
//  LGTeamDetailHeader.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/7/11.
//

#import "LGTeamDetailHeader.h"

@interface LGTeamDetailHeader()
/**   */
@property (nonatomic , strong)UIButton *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *editLabel;
/**   */
@property (nonatomic , strong)UILabel *countLabel;

@end

@implementation LGTeamDetailHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setIsManager:(BOOL)isManager{
    _isManager = isManager;
    self.editLabel.hidden = !isManager;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"name"]);
    NSString *content = LGNSString(dataDic[@"description"]);
    self.contentLabel.text = content;
    CGFloat conetentH = [content textHeightWithFont:LGFont(13) maxWidth:Screen_W-viewPix(136)];
    self.checkBtn.hidden = (conetentH>42)?NO:YES;
}

-(void)setCount:(NSInteger)count{
    _count = count;
    self.countLabel.text = [NSString stringWithFormat:@"团队成员（%ld）",count];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.baseView];
    [self addSubview:self.countLabel];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.editLabel];
    [self.baseView addSubview:self.detailBtn];
    [self.baseView addSubview:self.checkBtn];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView).offset(viewPix(1));
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(16));
        make.right.lessThanOrEqualTo(self.editLabel.mas_left).offset(-viewPix(3));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(5));
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.baseView).offset(-viewPix(18));
    }];
    [self.checkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self.contentLabel);
        make.width.equalTo(@(viewPix(50)));
        make.height.equalTo(@(18));
    }];
    [self.editLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(18));
        make.centerY.equalTo(self.titleLabel);
    }];
    [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self.editLabel);
        make.width.equalTo(@(viewPix(60)));
        make.height.equalTo(@(viewPix(30)));
    }];
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView.mas_bottom).offset(viewPix(18));
        make.left.equalTo(self.baseView);
    }];
    
}

-(UIButton *)baseView{
    if(!_baseView){
        _baseView = [UIButton buttonWithType:UIButtonTypeCustom];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(23), Screen_W-viewPix(32), viewPix(105));
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的团队"]];
        _iconView.frame = CGRectMake(viewPix(16), viewPix(20), viewPix(54), viewPix(54));
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#2B2A37" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)editLabel{
    if(!_editLabel){
        _editLabel = [UILabel lableWithText:@"编辑团队" colorString:kThemeColor textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _editLabel;
}

-(UIButton *)detailBtn{
    if(!_detailBtn){
        _detailBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    }
    return _detailBtn;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#61616D" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _contentLabel;
}

-(UILabel *)countLabel{
    if(!_countLabel){
        _countLabel = [UILabel lableWithText:@"" colorString:@"#61616D" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _countLabel;
}

-(UIButton *)checkBtn{
    if(!_checkBtn){
        _checkBtn = [UIButton buttonWithTitle:@"详情" titleFont:LGFont(14) textColor:kThemeColor imageName:@"themRightTip18"];
        _checkBtn.bounds = CGRectMake(0, 0, viewPix(50), 20);
        _checkBtn.backgroundColor = [UIColor whiteColor];
        [_checkBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
    }
    return _checkBtn;
}

@end
